package edu.whu.assignment5.repository;

import edu.whu.assignment5.dataobject.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface UserRepository extends JpaRepository<User, Integer> {
    User findByUid(int uid);

    User findByUsername(String username);

    @Transactional(rollbackFor = Exception.class)
    @Modifying
    @Query(nativeQuery = true, value = "insert into user_product_list (user_list_uid, product_list_pid) values (?1, ?2)")
    int insertUserAndProduct(int uid, int pid);
}
